package com.star.spring.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.star.spring.entity.UserEntity;
import com.star.spring.model.UserSearchDTO;
import com.star.spring.repository.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName UserService
 * @Author star
 * @Date 2024/7/14 18:52
 */
@Service
public class UserService extends ServiceImpl<UserMapper, UserEntity> implements IService<UserEntity> {

    @Autowired
    private UserMapper userMapper;

    public IPage<UserEntity> pageEntity(Page<UserEntity> page, UserSearchDTO searchDTO) {
        LambdaQueryWrapper<UserEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(searchDTO.getName() != null, UserEntity::getName, searchDTO.getName());
        wrapper.like(searchDTO.getCode() != null, UserEntity::getCode, searchDTO.getCode());

        IPage<UserEntity> userEntityIPage = userMapper.selectPage(page, wrapper);
        return userEntityIPage;
    }

    public int mapperSave(UserEntity saveReq){
        int insert = userMapper.insert(saveReq);
        return insert;
    }
}
